﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LanceZhang.Research.BLL;
using LanceZhang.Research.Model;

public partial class UserControl_ResearchParticular : System.Web.UI.UserControl
{
    TBL_Reserch rc = new TBL_Reserch();
    TBL_ReserchModel r = new TBL_ReserchModel();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null)
        {
            r = rc.GetModelByCache(Request.QueryString["id"]);

            lblName.Text = r.ResName;
            lblLevel.Text = r.LevelName;
            lblApplyDate.Text = r.ApplyDate.ToShortDateString();
            lblBegin.Text = r.BeginDate.ToShortDateString();
            lblIsDelay.Text = r.IsDelay.ToString();
            lblIsFin.Text = r.IsFinish.ToString();
            lblStartDate.Text = r.StartDate.ToShortDateString();
            lblVFin.Text = r.VFinDate.ToShortDateString();
            lblTFin.Text = r.TFinDate.ToShortDateString();
            lblTmoney.Text = r.TMomey.ToString();
            lblVmoney.Text = r.VMomey.ToString();
            liContent.Text = r.Content;
            hlview.Target = "_blank";
            hlview.NavigateUrl = "~/MyHonour.aspx?pid=" + r.ProjectID;

            TBL_User uc = new TBL_User();
            BulletedList1.DataSource = uc.GetList(" UserID in (Select UserID from TBL_ProjectMember where ProjectID='" + r.ProjectID + "')");
            BulletedList1.DataTextField = "UserName";
            BulletedList1.DataValueField = "UserID";
            BulletedList1.DataBind();

            lblManager.Text = uc.GetModelByCache(r.ManagerID).UserName;
            lblAppID.Text = uc.GetModelByCache(r.ApproverID).UserName;
            lblEndID.Text = uc.GetModelByCache(r.EndId).UserName;

            TBL_UserModel cu = (TBL_UserModel)Session["UM"];
            if(cu.UserID == r.ManagerID)
            {
                if (((r.StartDate.CompareTo(DateTime.Today))<0)&&(r.IsFinish==false))
                {
                    BtnOk.Enabled = true;
                }
                if (r.IsApprove == false)
                {
                    BtnUpdate.Enabled = true;
                }
            }

        }
    }
    protected void BtnUpdate_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddResearch.aspx?id=" + Request.QueryString["id"]);
    }
    protected void BtnOk_Click(object sender, EventArgs e)
    {
        r.IsFinish = true;
        r.TFinDate = DateTime.Today;
        r.IsDelay = (DateTime.Today.CompareTo(r.VFinDate) > 0);
        rc.Update(r);

        Page_Load(sender, e);

    }
}
